﻿using FluentAssertions;
using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.DataLayer;
using Sustainalytics.DataLayer.Shared;
using Sustainalytics.Entities;
using Sustainalytics.Entities.ProductInvolvement;
using Sustainalytics.Entities.SustainableProducts;
using Sustainalytics.MongoDB.Extensions;
using Sustainalytics.Portfolios.BL;
using Xunit;

namespace Sustainalytics.ScreeningTool.BL.Tests
{
    public class ExportScreeningTests
    {
        private readonly ExportScreening _target;

        public ExportScreeningTests()
        {
            const string connectionString = "mongodb://admin:G4nd4lf2014@54.171.12.91:27017";
            const string clientPlatformConnectionString = connectionString + "/ClientPlatform";
            const string clientDwConnectionString = connectionString + "/ClientDW_A";
            const string clientUniversesConnectionString = connectionString + "/ClientUniverses_A";
            const string ScreeningDataConnectionString = connectionString + "/ScreeningDW_A";

            var portfolioManager = new PortfolioReadHandler(
                new PortfolioTypeCollection<Portfolio>(new RepositoryCollection<Portfolio>(clientPlatformConnectionString), new RepositoryCollection<Portfolio>(clientPlatformConnectionString)),
                new PortfolioTypeCollection<PortfolioDetails>(new RepositoryCollection<PortfolioDetails>(clientPlatformConnectionString), new RepositoryCollection<PortfolioDetails>(clientPlatformConnectionString)),
                new RepositoryCollection<CorporateDataBasic>(clientDwConnectionString, "CorporateData"));

            var screeningDataRepository = ScreeningDataRepository.GetScreeningDataRepository(ScreeningDataConnectionString);

            _target = new ExportScreening(
                CompanyScreeningRepository.GetCompanyScreeningRepository(clientPlatformConnectionString),
                ClientDwRepository.GetInstance(clientDwConnectionString),
                portfolioManager,
                UniversesRepository.GetUniversesRepository(clientUniversesConnectionString),
                new FilterCriteriaRepository(clientPlatformConnectionString),
                new RepositoryCollection<CorporateData>(clientDwConnectionString),
                screeningDataRepository,
                MongoFactory.GetCollectionFromDatabase<CorporateData>(MongoFactory.GetConnectionStrings().ClientDW),
                MongoFactory.GetCollectionFromDatabase<SustainableProductsFramework>(MongoFactory.GetConnectionStrings().ProductInvolvementDW),
                MongoFactory.GetCollectionFromDatabase<ProductInvolvementFramework>(MongoFactory.GetConnectionStrings().ProductInvolvementDW));
        }

        [Fact]
        public void RunScreeningExportForFtpFailsOnStage()
        {
            _target.RunScreeningExportForFtp("45067234-4a25-417d-aa29-78cb2600d38f").Should().NotBeNull();
        }
    }
}
